const query = require('module/mysql-pool'); // 数据库模块

const dao = {};

/**
 * 详情
 * @param {String} id
 * @param {Function} callback 回调
 */
dao.detail = (id, callback) => {
  let sql = 'SELECT * FROM flash WHERE id=?';
  query(sql, [id], (err, result) => {
    let obj = result[0];
    if (obj) {
      ++obj.hits;
      // 更新-点击量
      let sqlNew = 'UPDATE flash SET hits=hits+1 WHERE id=?';
      query(sqlNew, [id], (err, result) => {});
    }
    callback(err, obj);
  });
}

module.exports = dao;